package com.jswdwsx.common.utils;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;

import java.lang.reflect.InvocationTargetException;

@Slf4j
public class EntityUtils {

    public static <T> T copy(Object source, Class<T> tClass, String... ignoreProperties) {
        try {
            T t = tClass.getDeclaredConstructor().newInstance();
            BeanUtils.copyProperties(source, t, ignoreProperties);
            return t;
        } catch (InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
            log.error("【系统异常】从" + source.getClass().getName() + "向" + tClass.getName() + "复制属性失败{}", e);
            throw new RuntimeException("系统异常");
        }
    }
}
